home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / New System Software Extensions / QuickDraw™ GX 1.1.2 / Programming Stuff / Sample Code / Graphics Samples / Spectacle ƒ / Object.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  2.4 KB  |  133 lines  |  [TEXT/KAHL]

  1. /*
  2.  *    Object.c
  3.  *
  4.  *    Robert Dierkes,  November 11, 1993
  5.  */
  6.  
  7. #include "graphics routines.h"
  8. #include "graphics libraries.h"
  9.  
  10. #include "ViewPorts.h"
  11. #include "Main.h"
  12. #include "Object.h"
  13.  
  14.  
  15. /*----------------------*/
  16. /*    Global Declarations    */
  17. /*----------------------*/
  18. gxPoint                gDistance;
  19. gxColor                gBackgroundColor;
  20.  
  21. /*------------------------------*/
  22. /*    External Declarations     */
  23. /*------------------------------*/
  24. extern    WindowPtr    gWindow;
  25. extern    gxShape        gFrame,
  26.                     gObject,
  27.                     gLastObject;
  28.  
  29.  
  30.  
  31. void SetSimpleColor (gxColor *pColor, commonColor someColor);
  32. void SetSimpleColor (gxColor *pColor, commonColor someColor)
  33. {
  34.     pColor->element.indexed.set   = commonColorSet;
  35.     pColor->element.indexed.index = someColor;
  36.     pColor->space   = gxIndexedSpace;
  37.     pColor->profile = nil;
  38.     pColor->element.rgb.red =
  39.     pColor->element.rgb.red =
  40.     pColor->element.rgb.red = 0xFFFF;
  41. }
  42.  
  43.  
  44. /*
  45.  *    Global:
  46.  *        gDistance
  47.  */
  48.     void
  49. InitializeObject (boolean isSquare, fixed width, fixed height, gxShape *pObject, gxShape *pLastObject)
  50. {
  51.     gxRectangle    bounds;
  52.  
  53.     if (pObject == nil)
  54.     {
  55.         DebugStr ("\pInitializeObject: pObject is nil");
  56.         return;
  57.     }
  58.  
  59.     DisposeShapeAt (pObject);
  60.  
  61.     bounds.left   =
  62.     bounds.top    = 0;
  63.     bounds.right  = width;
  64.     bounds.bottom = height;
  65.  
  66.     *pObject = isSquare ? GXNewRectangle (&bounds) : NewOval (&bounds);
  67.  
  68.     GXMoveShapeTo (*pObject, fixed1, fixed1);
  69.     SetShapeCommonColor (*pObject, lamp_black);
  70.  
  71.     DisposeShapeAt (pLastObject);
  72.     *pLastObject = GXNewShape (gxEmptyType);
  73.     SetSimpleColor (&gBackgroundColor, gxWhite);
  74.  
  75.     gDistance.x = width  >> 3;
  76.     gDistance.y = height >> 3;
  77. }
  78.  
  79.  
  80. /*
  81.  *    Globals:
  82.  *        gDistance
  83.  *        gObject
  84.  *        gLastObject
  85.  */
  86.     void
  87. MoveObject (void)
  88. {
  89.     gxRectangle    bounds;
  90.  
  91.     GXGetShapeBounds (gObject, 0, &bounds);
  92.  
  93.     /* Change direction if object reaches window edge */
  94.     if (bounds.left <= 0  ||
  95.         bounds.right >= IntToFixed (gWindow->portRect.right))
  96.     {
  97.         gDistance.x = - gDistance.x;
  98.     }
  99.  
  100.     if (bounds.top <=  0  ||
  101.         bounds.bottom >= IntToFixed (gWindow->portRect.bottom))
  102.     {
  103.         gDistance.y = - gDistance.y;
  104.     }
  105.  
  106.     GXDisposeShape (gLastObject);
  107.     gLastObject = CopyShape (gObject);
  108.     GXSetShapeColor (gLastObject, &gBackgroundColor);
  109.  
  110.     /* Move and draw new object */
  111.     GXMoveShape (gObject, gDistance.x, gDistance.y);
  112.  
  113.     /* Erase portion of previous object */
  114.     GXDifferenceShape (gLastObject, gObject);
  115.     GXDrawShape (gLastObject);
  116.  
  117.     GXDrawShape (gObject);
  118. }
  119.  
  120.  
  121.     void
  122. DrawObject (void)
  123. {
  124.     GXDrawShape (gObject);
  125. }
  126.  
  127.  
  128.     void
  129. DrawObjectFrame (void)
  130. {
  131.     GXDrawShape (gFrame);
  132. }
  133.